home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / doc / crosslib.doc < prev    next >
Text File  |  1996-07-24  |  46KB  |  1,570 lines

  1. /*
  2.  *   This file was automatically generated by version 1.6 of cextract.
  3.  *   Manual editing not recommended.
  4.  *
  5.  *   Created: Fri Jul 23 09:17:43 1993
  6.  */
  7. #ifndef __CEXTRACT__
  8. #if __STDC__
  9.  
  10. /*
  11.  * Initialises the internal linked list of archetypes (read from file).
  12.  * Then the global "empty_archetype" pointer is initialised.
  13.  * Then the blocksview[] array is initialised.
  14.  */
  15. void init_archetypes ( void );
  16.  
  17. /*
  18.  * Stores debug-information about how efficient the hashtable
  19.  * used for archetypes has been in the static errmsg array.
  20.  */
  21. void arch_info ( object *op );
  22.  
  23. /*
  24.  * Initialise the hashtable used by the archetypes.
  25.  */
  26. void clear_archetable ( void );
  27.  
  28. /*
  29.  * An alternative way to init the hashtable which is slower, but _works_...
  30.  */
  31. void init_archetable ( void );
  32.  
  33. /*
  34.  * Dumps an archetype to debug-level output.
  35.  */
  36. void dump_arch ( archetype *at );
  37.  
  38. /*
  39.  * Dumps _all_ archetypes to debug-level output.
  40.  * If you run crossfire with debug, and enter DM-mode, you can trigger
  41.  * this with the O key.
  42.  */
  43. void dump_all_archetypes ( void );
  44.  
  45. /*
  46.  * Allocates, initialises and returns the pointer to an archetype structure.
  47.  */
  48. archetype *get_archetype_struct ( void );
  49.  
  50. /*
  51.  * Reads/parses the archetype-file, and copies into a linked list
  52.  * of archetype-structures.
  53.  */
  54. void first_arch_pass ( FILE *fp );
  55.  
  56. /*
  57.  * Reads the archetype file once more, and links all pointers between
  58.  * archetypes.
  59.  */
  60. void second_arch_pass ( FILE *fp );
  61.  
  62. /*
  63.  * First initialises the archtype hash-table (init_archetable()).
  64.  * Reads and parses the archetype file (with the first and second-pass
  65.  * functions).
  66.  * Then initialises treasures by calling load_treasures().
  67.  */
  68. void load_archetypes ( void );
  69.  
  70. /*
  71.  * Creates and returns a new object which is a copy of the given archetype.
  72.  * This function returns NULL on failure.
  73.  */
  74. object *arch_to_object ( archetype *at );
  75.  
  76. /*
  77.  * Creates an object.  This function is called by get_archetype()
  78.  * if it fails to find the appropriate archetype.
  79.  * Thus get_archetype() will be guaranteed to always return
  80.  * an object, and never NULL.
  81.  */
  82. object *create_singularity ( char *name );
  83.  
  84. /*
  85.  * Finds which archetype matches the given name, and returns a new
  86.  * object containing a copy of the archetype.
  87.  */
  88. object *get_archetype ( char *name );
  89.  
  90. /*
  91.  * Finds the first archetype matching the given type, and returns the
  92.  * name of the object within the archetype.
  93.  * TODO: Redo missile weapons to use direct archetype-pointers, since
  94.  * that is the only thing left which uses this routine.
  95.  * (This routine uses too much cpu)
  96.  */
  97. char *get_archename ( int t );
  98.  
  99. /*
  100.  * Hash-function used by the arch-hashtable.
  101.  */
  102. unsigned long hasharch ( char *str );
  103.  
  104. /*
  105.  * Finds, using the hashtable, which archetype matches the given name.
  106.  * returns a pointer to the found archetype, otherwise NULL.
  107.  */
  108. archetype *find_archetype ( char *name );
  109.  
  110. /*
  111.  * Adds an archetype to the hashtable.
  112.  */
  113. void add_arch ( archetype *at );
  114.  
  115. /*
  116.  * Returns the first archetype using the given type.
  117.  * Used in treasure-generation.
  118.  */
  119. archetype *type_to_archetype ( int type );
  120.  
  121. /*
  122.  * Returns a new object copied from the first archetype matching
  123.  * the given type.
  124.  * Used in treasure-generation.
  125.  */
  126. object *clone_arch ( int type );
  127.  
  128. /*
  129.  * member: make instance from class
  130.  */
  131. object *ObjectCreateArch ( archetype * at );
  132.  
  133. /*
  134.  * Push the specified object.  This can affect other buttons/gates/handles
  135.  * altars/pedestals/holes in the whole map.
  136.  * Changed the routine to loop through _all_ objects.
  137.  * Better hurry with that linked list...
  138.  */
  139. void push_button ( object *op );
  140.  
  141. /*
  142.  * Updates everything connected with the button op.
  143.  * After changing the state of a button, this function must be called
  144.  * to make sure that all gates and other buttons connected to the
  145.  * button reacts to the (eventual) change of state.
  146.  */
  147. void update_button ( object *op );
  148.  
  149. /*
  150.  * Updates every button on the map (by calling update_button() for them).
  151.  */
  152. void update_buttons ( mapstruct *m );
  153.  
  154. void use_trigger ( object *op );
  155.  
  156. /* only one part objects */
  157. void animate_turning ( object *op );
  158.  
  159. /*
  160.  * check_altar checks if sacrifice was accepted and removes sacrificed
  161.  * objects. If sacrifice was succeed return 1 else 0
  162.  */
  163. int check_altar ( object *altar );
  164.  
  165. /* 1 down and 0 up */
  166. void trigger_move ( object *op, int state );
  167.  
  168. void check_trigger ( object *op );
  169.  
  170. void add_button_link ( object *button, mapstruct *map, int connected );
  171.  
  172. /*
  173.  * Remove the object from the linked lists of buttons in the map.
  174.  * This is only needed by editors.
  175.  */
  176. void remove_button_link ( object *op );
  177.  
  178. /*
  179.  * Return the first objectlink in the objects linked to this one
  180.  */
  181. objectlink *get_button_links ( object *button );
  182.  
  183. /*
  184.  * Made as a separate function to increase efficiency
  185.  */
  186. int get_button_value ( object *button );
  187.  
  188. /*
  189.  * nex_exp() is an alternative way to calculate experience based
  190.  * on the ability of a monster.
  191.  * It's far from perfect, and doesn't consider everything which
  192.  * can be considered, thus it's only used in debugging.
  193.  */
  194. int new_exp ( object *ob );
  195.  
  196. /*
  197.  * Returns true if the monster specified has any innate abilities.
  198.  */
  199. int has_ability ( object *ob );
  200.  
  201. /*
  202.  * Add a new friendly object to the linked list of friendly objects.
  203.  * No checking to see if the object is already in the linked list is done.
  204.  */
  205. void add_friendly_object ( object *op );
  206.  
  207. /*
  208.  * Removes the specified object from the linked list of friendly objects.
  209.  */
  210. void remove_friendly_object ( object *op );
  211.  
  212. /*
  213.  * Dumps all friendly objects.  Invoked in DM-mode with the G key.
  214.  */
  215. void dump_friendly_objects ( void );
  216.  
  217. /*
  218.  * Initialise all function-pointers to dummy-functions which will
  219.  * do nothing and return nothing (of value at least).
  220.  * Very healthy to do this when using the library, since
  221.  * function pointers are being called throughout the library, without
  222.  * being checked first.
  223.  * init_library() calls this function.
  224.  */
  225. void init_function_pointers ( void );
  226.  
  227. /*
  228.  * Specifies which function to call when there is an emergency save.
  229.  */
  230. void set_emergency_save ( void (*addr)(int) );
  231.  
  232. /*
  233.  * Specifies which function to call to clean temporary files.
  234.  */
  235. void set_clean_tmp_files ( void (*addr)() );
  236.  
  237. /*
  238.  * Specifies which function to call to fix auto-apply (objects which
  239.  * applies themselves when their map is loaded).
  240.  */
  241. void set_fix_auto_apply ( void (*addr)(mapstruct *) );
  242.  
  243. /*
  244.  * Specifies which function to call to remove an object in the
  245.  * linked list of friendly objects.
  246.  */
  247. void set_remove_friendly_object ( void (*addr)(object *) );
  248.  
  249. /*
  250.  * Specify which function to call to do some work in active
  251.  * maps.  That function might get called if there are several players,
  252.  * and one player is using too much cpu to either load a map, or to
  253.  * load pixmaps.
  254.  */
  255. void set_process_active_maps ( void (*addr)(void) );
  256.  
  257. /*
  258.  * Specify which function to call to recoordinate all buttons.
  259.  */
  260. void set_update_buttons ( void (*addr)(mapstruct *) );
  261.  
  262. /*
  263.  * Specify which function to call to draw text to the window
  264.  * of a player.
  265.  */
  266. void set_draw_info ( void (*addr)(object *, const char *) );
  267.  
  268. /*
  269.  * Specify which function to call to update the text in the
  270.  * stat-window of a player.
  271.  */
  272. void set_draw_stats ( void (*addr)(object *) );
  273.  
  274. /*
  275.  * Specify which function to call to update the graphics in the
  276.  * inventory-window of a player.
  277.  */
  278. void set_draw_inventory_faces ( void (*addr)(object *) );
  279.  
  280. /*
  281.  * Specify which function to call to update the graphics
  282.  * in the look-window of a player.
  283.  */
  284. void set_draw_look_faces ( void (*addr)(object *) );
  285.  
  286. /*
  287.  * Specify which function to call to update the content
  288.  * in the inventory-window of a player.
  289.  */
  290. void set_draw_inventory ( void (*addr)(object *) );
  291.  
  292. /*
  293.  * Specify which function to call to update the content
  294.  * of the look-window of a player.
  295.  */
  296. void set_draw_look ( void (*addr)(object *) );
  297.  
  298. /*
  299.  * Specify which function to call to apply an object.
  300.  */
  301. void set_apply ( int (*addr)(object *, object *) );
  302.  
  303. /*
  304.  * Specify which function to call to draw on the graphic-window
  305.  * of a player.
  306.  */
  307. void set_draw ( void (*addr)(object *) );
  308.  
  309. /*
  310.  * Specify which function to call to check if a monster can
  311.  * apply an object.
  312.  */
  313. void set_monster_check_apply ( object *(*addr)(object *, object *) );
  314.  
  315. /*
  316.  * Specify which functino to call to initialise the blocksview[] array.
  317.  */
  318. void set_init_blocksview_players ( void (*addr)(void) );
  319.  
  320. void set_info_map ( void (*addr)(mapstruct *, char *) );
  321.  
  322. /*
  323.  * fatal() is meant to be called whenever a fatal signal is intercepted.
  324.  * It will call the emergency_save and the clean_tmp_files functions.
  325.  */
  326. void fatal ( int err );
  327.  
  328. /*
  329.  * Dump to standard out the abilities of all monsters.
  330.  */
  331. void dump_abilities ( void );
  332.  
  333. /*
  334.  * As dump_abilities(), but with an alternative way of output.
  335.  */
  336. void print_monsters ( void );
  337.  
  338. /*
  339.  * Writes <num> ones and zeros to the given string based on the
  340.  * <bits> variable.
  341.  */
  342. void bitstostring ( long bits, int num, char *str );
  343.  
  344. /*
  345.  * It is vital that init_library() is called by any functions
  346.  * using this library.
  347.  * If you want to lessen the size of the program using the library,
  348.  * you can replase the call to init_library() with init_globals(),
  349.  * init_function_pointers() and init_defaults().
  350.  * (This is done in the client)
  351.  */
  352. void init_library ( void );
  353.  
  354. /*
  355.  * Initialises all global variables.
  356.  * Might use environment-variables as default for some of them.
  357.  */
  358. void init_globals ( void );
  359.  
  360. /*
  361.  * Sets up and initialises the linked list of free and used objects.
  362.  * Allocates a certain chunk of objects and puts them on the free list.
  363.  * Called by init_library();
  364.  */
  365. void init_objects ( void );
  366.  
  367. /*
  368.  * Initialises global variables which can be changed by options.
  369.  * Called by init_library().
  370.  */
  371. void init_defaults ( void );
  372.  
  373. /*
  374.  * query_weight(object) returns a character pointer to a static buffer
  375.  * containing the text-representation of the weight of the given object.
  376.  * The buffer will be overwritten by the next call to query_weight().
  377.  */
  378. char *query_weight ( object *op );
  379.  
  380. /*
  381.  * get_number(integer) returns the text-representation of the given number
  382.  * in a static buffer.  The buffer might be overwritten at the next
  383.  * call to get_number().
  384.  * It is currently only used by the query_name() function.
  385.  */
  386. char *get_number ( int i );
  387.  
  388. /*
  389.  * query_name(object) returns a character pointer pointing to a static
  390.  * buffer which contains a verbose textual representation of the name
  391.  * of the given object.  The buffer will be overwritten at the next
  392.  * call to query_name().
  393.  */
  394. char *query_name ( object *op );
  395.  
  396. /*
  397.  * Returns a pointer to a static buffer which contains a
  398.  * description of the given object.
  399.  * If it is a monster, lots of information about its abilities
  400.  * will be returned.
  401.  * If it is an item, lots of information about which abilities
  402.  * will be gained about its user will be returned.
  403.  * If it is a player, it writes out the current abilities
  404.  * of the player, which is usually gained by the items applied.
  405.  */
  406. char *describe_item ( object *op );
  407.  
  408. int always_magical ( object *op );
  409.  
  410. int need_identify ( object *op );
  411.  
  412. /*
  413.  * Supposed to fix face-values as well here, but later.
  414.  */
  415. void identify ( object *op );
  416.  
  417. /*
  418.  * Allocates a new objectlink structure, initialises it, and returns
  419.  * a pointer to it.
  420.  */
  421. objectlink *get_objectlink ( void );
  422.  
  423. /*
  424.  * Allocates a new oblinkpt structure, initialises it, and returns
  425.  * a pointer to it.
  426.  */
  427. oblinkpt *get_objectlinkpt ( void );
  428.  
  429. /*
  430.  * Recursively frees all objectlinks
  431.  */
  432. void free_objectlink ( objectlink *ol );
  433.  
  434. /*
  435.  * Recursively frees all linked list of objectlink pointers
  436.  */
  437. void free_objectlinkpt ( oblinkpt *obp );
  438.  
  439. /*
  440.  * sets Str/Dex/con/Wis/Cha/Int in stats to value, depending on
  441.  * what attr is (STR to INT).
  442.  */
  443. void set_attr_value ( living *stats, int attr, signed char value );
  444.  
  445. /*
  446.  * Like set_attr_value(), but instead the value (which can be negative)
  447.  * is added to the specified stat.
  448.  */
  449. void change_attr_value ( living *stats, int attr, signed char value );
  450.  
  451. /*
  452.  * returns the specified stat.  See also set_attr_value().
  453.  */
  454. signed char get_attr_value ( living *stats, int attr );
  455.  
  456. /*
  457.  * Ensures that all stats (str/dex/con/wis/cha/int) are within the stat limit.
  458.  */
  459. void check_stat_bounds ( object *op );
  460.  
  461. /*
  462.  * Adds abilities to the first object based on what the second object
  463.  * gives to appliers.  If the second object does not have the APPLIED
  464.  * flag set, it is assumed that it is being unapplied, and any abilities
  465.  * it gives are subtracted from the first object.
  466.  * (This is of course a problem now, since several objects may give
  467.  * the same abilities, thus change_abil() is used mostly to display
  468.  * messages, while fix_player() is called afterwards.)
  469.  * Also writes a more or less informative message to the first object
  470.  * about what abilities were gained/lost.
  471.  */
  472. int change_abil ( object *op, object *tmp );
  473.  
  474. /*
  475.  * Stat draining by Vick 930307
  476.  * (Feeling evil, I made it work as well now.  -Frank 8)
  477.  */
  478. void drain_stat ( object *op );
  479.  
  480. void drain_specific_stat ( object *op, int deplete_stats );
  481.  
  482. /*
  483.  * A value of 0 indicates timeout, otherwise change the luck of the object.
  484.  * via an applied bad_luck object.
  485.  */
  486. void change_luck ( object *op, int value );
  487.  
  488. /*
  489.  * Subtracts stat-bonuses given by the class which the player has chosen.
  490.  */
  491. void remove_statbonus ( object *op );
  492.  
  493. /*
  494.  * Adds stat-bonuses given by the class which the player has chosen.
  495.  */
  496. void add_statbonus ( object *op );
  497.  
  498. /*
  499.  * Updates all abilities given by applied objects in the inventory
  500.  * of the given object.  Note: This function works for both monsters
  501.  * and players; the "player" in the name is purely an archaic inheritance.
  502.  */
  503. void fix_player ( object *op );
  504.  
  505. /*
  506.  * Returnes true if the given player is a legal class.
  507.  * The function to add and remove class-bonuses to the stats doesn't
  508.  * check if the stat becomes negative, thus this function
  509.  * merely checks that all stats are 1 or more, and returns
  510.  * false otherwise.
  511.  */
  512. int allowed_class ( object *op );
  513.  
  514. /*
  515.  * Returns how much experience is needed for a player to become
  516.  * the given level.
  517.  */
  518. int level_exp ( int level );
  519.  
  520. /*
  521.  * Adds (or subtracts) experience to a living object.  If it is a player,
  522.  * checks for level-gain/loss is done.
  523.  * The routines for gaining/losing levels is also within this function.
  524.  */
  525. void add_exp ( object *op, int exp );
  526.  
  527. /*
  528.  * Initialises the array of variable-names.  Needed before any
  529.  * objects can be loaded.  Called by init_library().
  530.  */
  531. void init_vars ( void );
  532.  
  533. /*
  534.  * Searches through all possible variables to find any that matches
  535.  * the given string.  An index to the variable_const[] array is returned,
  536.  * or -1 on failure.
  537.  */
  538. int get_variable ( char *name );
  539.  
  540. /*
  541.  * Returns a pointer to a static string which contains all variables
  542.  * which are different in the two given objects.
  543.  */
  544. char *get_ob_diff ( object *op, object *op2 );
  545.  
  546. /*
  547.  * Dumps all variables in an object to a file.
  548.  * If big 0 of flag is set, do a raw save without any checks.
  549.  * If bit 1 of flag is set, don't remove the object after save.
  550.  */
  551. void save_object ( FILE *fp, object *op, int flag );
  552.  
  553. /*
  554.  * Returns true if the given color exists in the internal list
  555.  * of legal colors.
  556.  */
  557. char find_color ( char *name );
  558.  
  559. /*
  560.  * set_variable() expects buf to be a line with two arguments, the first
  561.  * being a variable and the second being the value (which can be anything from
  562.  * an integer to a string). 
  563.  * The object given will have the given variable modified.
  564.  *
  565.  * -1 will be returned if there is no such variable
  566.  * 0 will be returned if the variable is to be ignored
  567.  * 1 will be returned if the variable was "anim"
  568.  * 2 will be returned if the variable was "end"
  569.  * 3 will be returned if the variable was "Inventory"
  570.  * 4 will be returned if the variable was "More"
  571.  * 5 will be returned if the variable was "msg"
  572.  * 6 will be returned if the variable was "endmsg"
  573.  * otherwise 0 will be returned
  574.  */
  575. int set_variable ( object *op, char *buf );
  576.  
  577. /*
  578.  * Loads an object from the given file-pointer.
  579.  * Variables will be read and parsed and patched into the object
  580.  * until the string "end" is reached, or the end of the file.
  581.  * If EOF is reached, it returnes false, otherwise true.
  582.  */
  583. int load_object ( FILE *fp, object *op );
  584.  
  585. /*
  586.  * Logs a message to stderr, or to file, and/or even to socket.
  587.  * Or discards the message if it is of no importanse, and none have
  588.  * asked to hear messages of that logLevel.
  589.  * logLevels can be logError (always printed), llevDebug, and llevMonster.
  590.  */
  591. void LOG ( LogLevel logLevel, char *format, ... );
  592.  
  593. /*
  594.  * Used to initialise the array used by the LOS routines.
  595.  */
  596. void set_block ( int x, int y, int bx, int by );
  597.  
  598. /*
  599.  * initialises the array used by the LOS routines.
  600.  */
  601. void init_block ( void );
  602.  
  603. /*
  604.  * Used to initialise the array used by the LOS routines.
  605.  */
  606. void set_wall ( object *op, int x, int y );
  607.  
  608. /*
  609.  * Used to initialise the array used by the LOS routines.
  610.  */
  611. void check_wall ( object *op, int x, int y );
  612.  
  613. /*
  614.  * Clears/initialises the los-array associated to the player
  615.  * controlling the object.
  616.  */
  617. void clear_los ( object *op );
  618.  
  619. /*
  620.  * expand_sight goes through the array of what the given player is
  621.  * able to see, and expands the visible area a bit, so the player will,
  622.  * to a certain degree, be able to see into corners.
  623.  * This is somewhat suboptimal, would be better to improve the formula.
  624.  * There are two versions of this function, based on wheter or not
  625.  * CD_LINE_OF_SIGHT is defined.  If it is defined, the function
  626.  * becomes a bit more time-consuming, but covers a few more "corners"...
  627.  */
  628. void expand_sight ( object *op );
  629.  
  630. /*
  631.  * update_los() recalculates the array which specifies what is
  632.  * visible for the given player-object.
  633.  */
  634. void update_los ( object *op );
  635.  
  636. /*
  637.  * This function makes sure that update_los() will be called for all
  638.  * players on the given map within the next frame.
  639.  * It is triggered by removal or inserting of objects which blocks
  640.  * the sight in the map.
  641.  */
  642. void update_all_los ( mapstruct *map );
  643.  
  644. /*
  645.  * Debug-routine which dumps the array which specifies the visible
  646.  * area of a player.  Triggered by the z key in DM mode.
  647.  */
  648. void print_los ( object *op );
  649.  
  650. /*
  651.  * check_face_range() is used from init_blocksview() to avoid
  652.  * crashing the game due to buggy data in the archetype file.
  653.  * Must maintain some sanity in this madness... 8)
  654.  */
  655. int check_face_range ( Fontindex face, char *name );
  656.  
  657. /*
  658.  * init_blocksview() fills an array (blocksview[]) with information
  659.  * about which characters/pixmaps are blocking views.
  660.  * This doesn't handle all cases (dropping a coin on top of a mountain),
  661.  * but it's much faster than checking all the objects for BLOCKS_VIEW().
  662.  */
  663. void init_blocksview ( void );
  664.  
  665. /*
  666.  * make_sure_seen: The object is supposed to be visible through walls, thus
  667.  * check if any players are nearby, and edit their LOS array.
  668.  */
  669. void make_sure_seen ( object *op );
  670.  
  671. /*
  672.  * make_sure_not_seen: The object which is supposed to be visible through
  673.  * walls has just been removed from the map, so update the los of any
  674.  * players within its range
  675.  */
  676. void make_sure_not_seen ( object *op );
  677.  
  678. /*
  679.  * returns a char-pointer to a static array, in which a representation
  680.  * of the decimal number given will be stored.
  681.  */
  682. char *ltostr10 ( signed long n );
  683.  
  684. /*
  685.  * A fast routine which appends the name and decimal number specified
  686.  * to the given buffer.
  687.  * Could be faster, though, if the strcat()s at the end could be changed
  688.  * into alternate strcat which returned a pointer to the _end_, not the
  689.  * start!
  690.  */
  691. void save_long ( char *buf, char *name, long n );
  692.  
  693. /*
  694.  * Returns the mapstruct which has a name matching the given argument.
  695.  */
  696. mapstruct *has_been_loaded ( char *name );
  697.  
  698. /*
  699.  * This makes a path absolute outside the world of Crossfire.
  700.  * In other words, it prepends LIBDIR/MAPDIR/ to the given path
  701.  * and returns the pointer to a static array containing the result.
  702.  */
  703. char *create_pathname ( char *name );
  704.  
  705. /*
  706.  * This program checks if a file with the given path exists.
  707.  * -1 is returned if it failes, otherwise the mode of the file
  708.  * is returned.
  709.  */
  710. int check_path ( char *name );
  711.  
  712. /*
  713.  * Prints out debug-information about a map.
  714.  */
  715. void dump_map ( mapstruct *m );
  716.  
  717. /*
  718.  * Prints otu debug-information about all maps.
  719.  */
  720. void dump_all_maps ( void );
  721.  
  722. /*
  723.  * Returns true if a wall is present in a given location.
  724.  */
  725. int wall ( mapstruct *m, int x, int y );
  726.  
  727. /*
  728.  * Returns true if it's impossible to see through the given coordinate
  729.  * in the given map.
  730.  */
  731. int blocks_view ( mapstruct *m, int x, int y );
  732.  
  733. /*
  734.  * Returns true if the given coordinate in the given map blocks magic.
  735.  */
  736. int blocks_magic ( mapstruct *m, int x, int y );
  737.  
  738. /*
  739.  * Returns true if the given coordinate in the given map blocks passage.
  740.  */
  741. int blocked ( mapstruct *m, int x, int y );
  742.  
  743. /*
  744.  * Returns true if the given coordinate in the map where the given object
  745.  * is, blocks the given object (which may be multi-part)
  746.  */
  747. int blocked_link ( object *ob, int x, int y );
  748.  
  749. /*
  750.  * Eneq(@csd.uu.se): This is a new version of blocked, this one handles objects
  751.  * that can be passed through by monsters with the CAN_PASS_THRU defined.
  752.  */
  753. int blocked_two ( object *op, int x, int y );
  754.  
  755. /*
  756.  * Returns true if the given archetype can't fit in the given spot.
  757.  */
  758. int arch_blocked ( archetype *at, mapstruct *m, int x, int y );
  759.  
  760. /*
  761.  * Returns true if the given archetype can't fit into the map at the
  762.  * given spot (some part of it is outside the map-boundaries).
  763.  */
  764. int arch_out_of_map ( archetype *at, mapstruct *m, int x, int y );
  765.  
  766. /*
  767.  * Goes through all objects in the given map, and does a sanity-check
  768.  * on all pointers.
  769.  */
  770. void refresh_map ( mapstruct *m );
  771.  
  772. /*
  773.  * open_and_uncompress() first searches for the original filename.
  774.  * if it exist, then it opens it and returns the file-pointer.
  775.  * if not, it does two things depending on the flag.  If the flag
  776.  * is set, it tries to create the original file by uncompressing a .Z file.
  777.  * If the flag is not set, it creates a temporarily file and uncompresses
  778.  * the .Z file into that file.  The temporary file will be deleted in
  779.  * close_and_delete().
  780.  * (Note, the COMPRESS_SUFFIX is used instead of ".Z", thus it can easily
  781.  * be changed in the config file.)
  782.  */
  783. FILE *open_and_uncompress ( char *name, int flag, int *compressed );
  784.  
  785. /*
  786.  * See open_and_uncompress().
  787.  */
  788. void close_and_delete ( FILE *fp );
  789.  
  790. /*
  791.  * Loads (ands parses) the objects into a given map from the specified
  792.  * file pointer.
  793.  * If block is true, the game will be blocked until all objects have
  794.  * been loaded (this is needed to avoid certain critical regions).
  795.  */
  796. void load_objects ( mapstruct *m, FILE *fp, int block );
  797.  
  798. void save_objects ( mapstruct *m, FILE *fp );
  799.  
  800. /*
  801.  * Opens the file "filename" and reads information about the map
  802.  * from the given file, and stores it in a newly allocated
  803.  * mapstruct.  A pointer to this structure is returned, or NULL on failure.
  804.  * If block is true, it will block the game while reading the objects.
  805.  */
  806. mapstruct *load_original_map ( char *filename, int block );
  807.  
  808. /*
  809.  * Loads a map, which has been loaded earlier, from file.
  810.  */
  811. void load_temporary_map ( mapstruct *m );
  812.  
  813. void queue_push ( object* m_ob );
  814.  
  815. object *queue_pop ( void );
  816.  
  817. /*
  818.  * Saves a map to file.  If flag is set, it is saved into the same
  819.  * file it was (originally) loaded from.  Otherwise a temporary
  820.  * filename will be genarated, and the file will be stored there.
  821.  * The temporary filename will be stored in the mapstructure.
  822.  */
  823. void new_save_map ( mapstruct *m, int flag );
  824.  
  825. /*
  826.  * If any directories in the given path doesn't exist, they are created.
  827.  */
  828. void make_path_to_file ( char *filename );
  829.  
  830. /*
  831.  * Used to fix an ancient bug in old maps.
  832.  * Will soon be obsolete.
  833.  */
  834. void check_background ( mapstruct *m, int x, int y );
  835.  
  836. /*
  837.  * Clears the arrays containing object-pointers and outlook of a map.
  838.  */
  839. void clear_map ( mapstruct *m );
  840.  
  841. /*
  842.  * This function relinks all _pointers_ to the objects from
  843.  * one map to another.
  844.  * Note: You can _not_ free the objects in the original map
  845.  * after this function has been called.
  846.  * (What happened to this function? It no longer copies the pointers! -Frank)
  847.  */
  848. void copy_map ( mapstruct *m1, mapstruct *m2 );
  849.  
  850. /*
  851.  * This function, like copy_map(), relinks all _pointers_ from
  852.  * one map to the other map.
  853.  */
  854. void relink_objs_offset ( mapstruct *m1, mapstruct *m2, int dx, int dy );
  855.  
  856. /*
  857.  * Remove and free all objects in the inventory of the given object.
  858.  */
  859. void clean_object ( object *op );
  860.  
  861. /*
  862.  * Remove and free all objects in the given map.
  863.  */
  864. void free_all_objects ( mapstruct *m );
  865.  
  866. /*
  867.  * This function moves all objects from one map to another.
  868.  *
  869.  * move_all_objects(): Only used from the editor(s?)
  870.  * Yes. -Frank
  871.  */
  872. void move_all_objects ( mapstruct *m1, mapstruct *m2 );
  873.  
  874. /*
  875.  * function: vanish mapstruct
  876.  * m       : pointer to mapstruct, if NULL no action
  877.  */
  878. void delete_map ( mapstruct *m );
  879.  
  880. /*
  881.  * Frees everything allocated by the given mapstructure.
  882.  */
  883. void free_map ( mapstruct *m, int flag );
  884.  
  885. /*
  886.  * If there is a global message in the map where the given object is,
  887.  * display the message to the object.
  888.  */
  889. void draw_map_message ( object *op );
  890.  
  891. /*
  892.  * Allocates, initialises, and returns a pointer to a mapstruct.
  893.  */
  894. mapstruct *get_linked_map ( char *path );
  895.  
  896. /*
  897.  * Allocates the arrays contained in a mapstruct.
  898.  */
  899. void allocate_map ( mapstruct *m );
  900.  
  901. /*
  902.  * Creates an empty map of the given size, and returns a pointer to it.
  903.  */
  904. mapstruct *get_empty_map ( int sizex, int sizey );
  905.  
  906. /*
  907.  * An obsolete function, replaced by ready_map_name().
  908.  */
  909. mapstruct *ready_map ( int level, int flag );
  910.  
  911. /*
  912.  * Makes sure the given map is loaded and swapped in.
  913.  * Returns a pointer to the given map.
  914.  */
  915. mapstruct *ready_map_name ( char *name, int flush );
  916.  
  917. void no_maps_file ( char *filename );
  918.  
  919. void find_first_level ( char *path );
  920.  
  921. char *find_map_name ( int level );
  922.  
  923. void update_map_name ( int level, char *name );
  924.  
  925. void set_map_reset_time ( mapstruct *map );
  926.  
  927. /*
  928.  * This routine is supposed to find out which level the players should have
  929.  * before visiting this map.  It is used to calculate which bonuses to put
  930.  * on magic items.
  931.  */
  932. int calculate_difficulty ( mapstruct *m );
  933.  
  934. void clean_tmp_map ( mapstruct *m );
  935.  
  936. object * MapGetObjectZ ( mapstruct * emap, int x, int y, int z );
  937.  
  938. /*
  939.  * member: copy by translate objects from source to target
  940.  * target: -map
  941.  * source: -map
  942.  * dx    : positive translate to right
  943.  * dy    : positive translate to down
  944.  */
  945. void MapMoveScroll ( mapstruct *target, mapstruct *source, int dx, int dy );
  946.  
  947. object * MapGetRealObject ( mapstruct * emap, int x, int y, int z );
  948.  
  949. int MapInsertObjectZ ( mapstruct *emap, object *o, int x, int y, int z );
  950.  
  951. int MapObjectOut ( mapstruct *target, object *obj, int x, int y );
  952.  
  953. /*
  954.  * Eneq(@csd.uu.se): Since we can have items buried in a character we need
  955.  * a better check
  956.  */
  957. object *is_player_inv ( object *op );
  958.  
  959. /*
  960.  * Used by Crossedit?
  961.  * The result of the dump is stored in the static global errmsg array.
  962.  */
  963. void dump_object2 ( object *op );
  964.  
  965. /*
  966.  * Dumps an object.  Returns output in the static global errmsg array.
  967.  */
  968. void dump_object ( object *op );
  969.  
  970. /*
  971.  * This is really verbose...Can be triggered by the P key while in DM mode.
  972.  * All objects are dumped to stderr (or alternate logfile, if in server-mode)
  973.  */
  974. void dump_all_objects ( void );
  975.  
  976. /*
  977.  * animate_object(object) updates the face-variable of an object.
  978.  * If the object is the head of a multi-object, all objects are animated.
  979.  * If the object has the IS_TURNING() flag, that is taken into consideration.
  980.  */
  981. void animate_object ( object *op );
  982.  
  983. /*
  984.  * get_nearest_part(multi-object, object 2) returns the part of the
  985.  * multi-object 1 which is closest to the second object.
  986.  * If it's not a multi-object, it is returned.
  987.  */
  988. object *get_nearest_part ( object *op, object *pl );
  989.  
  990. /*
  991.  * Returns the object which has the count-variable equal to the argument.
  992.  */
  993. object *find_object ( int i );
  994.  
  995. /*
  996.  * Returns the first object which has a name equal to the argument.
  997.  * Used only by the patch command, but not all that useful.
  998.  * Enables features like "patch <name-of-other-player> food 999"
  999.  */
  1000. object *find_object_name ( char *str );
  1001.  
  1002. /*
  1003.  * Returns the object which this object marks as being the owner.
  1004.  * A id-scheme is used to avoid pointing to objects which have been
  1005.  * freed and are now reused.  If this is detected, the owner is
  1006.  * set to NULL, and NULL is returned.
  1007.  * (This scheme should be changed to a refcount scheme in the future)
  1008.  */
  1009. object *get_owner ( object *op );
  1010.  
  1011. /*
  1012.  * Sets the owner of the first object to the second object.
  1013.  * Also checkpoints a backup id-scheme which detects freeing (and reusage)
  1014.  * of the owner object.
  1015.  * See also get_owner() and unset_owner().
  1016.  */
  1017. void set_owner ( object *op, object *owner );
  1018.  
  1019. /*
  1020.  * Resets vital variables in an object
  1021.  */
  1022. void reset_object ( object *op );
  1023.  
  1024. /*
  1025.  * clear_object() frees everything allocated by an object, and also
  1026.  * clears all variables and flags to default settings.
  1027.  */
  1028. void clear_object ( object *op );
  1029.  
  1030. /*
  1031.  * copy object first frees everything allocated by the second object,
  1032.  * and then copies the contends of the first object into the second
  1033.  * object, allocating what needs to be allocated.
  1034.  */
  1035. void copy_object ( object *op2, object *op );
  1036.  
  1037. /*
  1038.  * expand_objects() allocates more objects for the list of unused objects.
  1039.  * It is called from get_object() if the list unused list is empty.
  1040.  */
  1041. void expand_objects ( void );
  1042.  
  1043. /*
  1044.  * get_object() grabs an object from the list of unused objects, makes
  1045.  * sure it is initialised, and returns it.
  1046.  * If there are no free objects, expand_objects() is called to get more.
  1047.  */
  1048. object *get_object ( void );
  1049.  
  1050. /*
  1051.  * If an object with the IS_TURNABLE() flag needs to be turned due
  1052.  * to the closest player being on the other side, this function can
  1053.  * be called to update the face variable, _and_ how it looks on the map.
  1054.  */
  1055. void update_turn_face ( object *op );
  1056.  
  1057. /*
  1058.  * update_object() updates the array which represents the map.
  1059.  * It takes into account invisible objects (and represent squares covered
  1060.  * by invisible objects by whatever is below them (unless it's another
  1061.  * invisible object, etc...))
  1062.  * If the object being updated is beneath a player, the look-window
  1063.  * of that player is updated (this might be a suboptimal way of
  1064.  * updating that window, though, since update_object() is called _often_)
  1065.  */
  1066. void update_object ( object *op );
  1067.  
  1068. /*
  1069.  * free_object() frees everything allocated by an object, removes
  1070.  * it from the list of used objects, and puts it on the list of
  1071.  * free objects.  The IS_FREED() flag is set in the object.
  1072.  * The object must have been removed by remove_ob() first for
  1073.  * this function to succeed.
  1074.  */
  1075. void free_object ( object *ob );
  1076.  
  1077. /*
  1078.  * count_free() returns the number of objects on the list of free objects.
  1079.  */
  1080. int count_free ( void );
  1081.  
  1082. /*
  1083.  * count_used() returns the number of objects on the list of used objects.
  1084.  */
  1085. int count_used ( void );
  1086.  
  1087. /*
  1088.  * sub_weight() recursively (outwards) subtracts a number from the
  1089.  * weight of an object (and what is carried by it's environment(s)).
  1090.  */
  1091. void sub_weight ( object *op, signed long weight );
  1092.  
  1093. /* remove_ob(op):
  1094.  *   This function removes the object op from the linked list of objects
  1095.  *   which it is currently tied to.  When this function is done, the
  1096.  *   object will have no environment.  If the object previously had an
  1097.  *   environment, the x and y coordinates will be updated to
  1098.  *   the previous environment.
  1099.  *   Beware: This function is called from the editor as well!
  1100.  */
  1101. void remove_ob ( object *op );
  1102.  
  1103. /*
  1104.  * merge_ob(op,top):
  1105.  *
  1106.  * This function goes through all objects below and including top, and
  1107.  * merges op to the first matching object.
  1108.  * If top is NULL, it is calculated.
  1109.  * Returns true if it succeded in the merge.
  1110.  */
  1111. int merge_ob ( object *op, object *top );
  1112.  
  1113. /*
  1114.  * insert_ob_in_map(op, map):
  1115.  * This function inserts the object in the two-way linked list
  1116.  * which represents what is on a map.
  1117.  * The second argument specifies the map, and the x and y variables
  1118.  * in the object about to be inserted specifies the position.
  1119.  */
  1120. void insert_ob_in_map ( object *op, mapstruct *m );
  1121.  
  1122. /*
  1123.  * get_split_ob(ob,nr) splits up ob into two parts.  The part which
  1124.  * is returned contains nr objects, and the remaining parts contains
  1125.  * the rest (or is removed and freed if that number is 0).
  1126.  * On failure, NULL is returned, and the reason put into the
  1127.  * global static errmsg array.
  1128.  */
  1129. object *get_split_ob ( object *orig_ob, int nr );
  1130.  
  1131. /*
  1132.  * decrease_ob_nr(object, number) decreases a specified number from
  1133.  * the amount of an object.  If the amount reaches 0, the object
  1134.  * is subsequently removed and freed.
  1135.  */
  1136. void decrease_ob_nr ( object *op, int i );
  1137.  
  1138. /*
  1139.  * decrease_ob(object) works like decrease_ob_nr(object, 1).
  1140.  */
  1141. void decrease_ob ( object *op );
  1142.  
  1143. /*
  1144.  * add_weight(object, weight) adds the specified weight to an object,
  1145.  * and also updates how much the environment(s) is/are carrying.
  1146.  */
  1147. void add_weight ( object *op, signed long weight );
  1148.  
  1149. /*
  1150.  * insert_ob_in_ob(op,environment):
  1151.  *   This function inserts the object op in the linked list
  1152.  *   inside the object environment.  If environment is NULL,
  1153.  *   the object will be stacked at the map.
  1154.  *
  1155.  *
  1156.  * Eneq(@csd.uu.se): Altered insert_ob_in_ob to make things picked up enter 
  1157.  * the inventory at the last position or next to other objects of the same
  1158.  * type.
  1159.  * Frank: Now sorted by type, archetype and magic!
  1160.  */
  1161. void insert_ob_in_ob ( object *op, object *where );
  1162.  
  1163. /*
  1164.  * Checks if any objects which has the WALK_ON() (or FLY_ON() if the
  1165.  * object is flying) flag set, will be auto-applied by the insertion
  1166.  * of the object into the map (applying is instantly done).
  1167.  * Any speed-modification due to SLOW_MOVE() of other present objects
  1168.  * will affect the speed_left of the object.
  1169.  */
  1170. void check_walk_on ( object *op );
  1171.  
  1172. /*
  1173.  * present_arch(arch, map, x, y) searches for any objects with
  1174.  * a matching archetype at the given map and coordinates.
  1175.  * The first matching object is returned, or NULL if none.
  1176.  */
  1177. object *present_arch ( archetype *at, mapstruct *m, int x, int y );
  1178.  
  1179. /*
  1180.  * present(type, map, x, y) searches for any objects with
  1181.  * a matching type variable at the given map and coordinates.
  1182.  * The first matching object is returned, or NULL if none.
  1183.  */
  1184. object *present ( unsigned char type, mapstruct *m, int x, int y );
  1185.  
  1186. /*
  1187.  * present_in_ob(type, object) searches for any objects with
  1188.  * a matching type variable in the inventory of the given object.
  1189.  * The first matching object is returned, or NULL if none.
  1190.  */
  1191. object *present_in_ob ( unsigned char type, object *op );
  1192.  
  1193. /*
  1194.  * present_arch_in_ob(archetype, object) searches for any objects with
  1195.  * a matching archetype in the inventory of the given object.
  1196.  * The first matching object is returned, or NULL if none.
  1197.  */
  1198. object *present_arch_in_ob ( archetype *at, object *op );
  1199.  
  1200. /*
  1201.  * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in
  1202.  * all it's inventory (recursively).
  1203.  * If checksums are used, a player will get set_cheat called for
  1204.  * him/her-self and all object carried by a call to this function.
  1205.  */
  1206. void set_cheat ( object *op );
  1207.  
  1208. /*
  1209.  * find_free_spot(archetype, map, x, y, start, stop) will search for
  1210.  * a spot at the given map and coordinates which will be able to contain
  1211.  * the given archetype.  start and stop specifies how many squares
  1212.  * to search (see the freearr_x/y[] definition).
  1213.  * It returns a random choice among the alternatives found.
  1214.  */
  1215. int find_free_spot ( archetype *at, mapstruct *m, int x, int y, int
  1216.                      start, int stop );
  1217.  
  1218. /*
  1219.  * find_first_free_spot(archetype, mapstruct, x, y) works like
  1220.  * find_free_spot(), but it will search max number of squares.
  1221.  * But it will return the first available spot, not a random choice.
  1222.  */
  1223. int find_first_free_spot ( archetype *at, mapstruct *m, int x, int y );
  1224.  
  1225. /*
  1226.  * find_dir(map, x, y, exclude) will search some close squares in the
  1227.  * given map at the given coordinates for live objects.
  1228.  * It will not considered the object given as exlude among possible
  1229.  * live objects.
  1230.  * It returns the direction toward the first/closest live object if finds
  1231.  * any, otherwise 0.
  1232.  */
  1233. int find_dir ( mapstruct *m, int x, int y, object *exclude );
  1234.  
  1235. /*
  1236.  * distance(object 1, object 2) will return the square of the
  1237.  * distance between the two given objects.
  1238.  */
  1239. int distance ( object *ob1, object *ob2 );
  1240.  
  1241. /*
  1242.  * find_dir_2(delta-x,delta-y) will return a direction in which
  1243.  * an object which has subtracted the x and y coordinates of another
  1244.  * object, needs to travel toward it.
  1245.  */
  1246. int find_dir_2 ( int x, int y );
  1247.  
  1248. /*
  1249.  * absdir(int): Returns a number between 1 and 8, which represent
  1250.  * the "absolute" direction of a number (it actually takes care of
  1251.  * "overflow" in previous calculations of a direction).
  1252.  */
  1253. int absdir ( int d );
  1254.  
  1255. /*
  1256.  * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
  1257.  * between two directions (which are expected to be absolute (see absdir())
  1258.  */
  1259. int dirdiff ( int dir1, int dir2 );
  1260.  
  1261. /*
  1262.  * can_pick(picker, item): finds out if an object is possible to be
  1263.  * picked up by the picker.  Returnes 1 on success, otherwise 0.
  1264.  */
  1265. int can_pick ( object *who, object *item );
  1266.  
  1267. /*
  1268.  * create clone from object to another
  1269.  */
  1270. object *ObjectCreateClone ( object *asrc );
  1271.  
  1272. /*
  1273.  * Returns a newly allocated and initialised and correctly
  1274.  * linked player structure.
  1275.  */
  1276. player *get_player_ob ( void );
  1277.  
  1278. void free_player ( player *pl );
  1279.  
  1280. /* re-cmp - get regular expression match.
  1281.  * Return values: NULL - no match or error in regexp.
  1282.  *                pointer to beginning of matching string
  1283.  */
  1284. char * re_cmp ( char *str, char *regexp );
  1285.  
  1286. /*
  1287.  * Initialises the hash-table used by the shared string library.
  1288.  */
  1289. void init_hash_table ( void );
  1290.  
  1291. /*
  1292.  * Hashing-function used by the shared string library.
  1293.  */
  1294. int hashstr ( char *str );
  1295.  
  1296. /*
  1297.  * Allocates and initialises a new shared_string structure, containing
  1298.  * the string str.
  1299.  */
  1300. shared_string * new_shared_string ( char *str );
  1301.  
  1302. /*
  1303.  * Description:
  1304.  *      This will add 'str' to the hash table. If there's no entry for this
  1305.  *      string, a copy will be allocated, and a pointer to that is returned.
  1306.  * Return values:
  1307.  *      - pointer to string identical to str
  1308.  */
  1309. char * add_string ( char *str );
  1310.  
  1311. /*
  1312.  * Description:
  1313.  *      This will increase the refcount of the string str, which *must*
  1314.  *      have been returned from a previous add_string().
  1315.  * Return values:
  1316.  *      - str
  1317.  */
  1318. char * add_refcount ( char *str );
  1319.  
  1320. /*
  1321.  * Description:
  1322.  *      This will see if str is in the hash table, and return the address
  1323.  *      of that string if it exists.
  1324.  * Return values:
  1325.  *      - pointer to identical string or NULL
  1326.  */
  1327. char * find_string ( char *str );
  1328.  
  1329. void free_string ( char *str );
  1330.  
  1331. /*
  1332.  * Description:
  1333.  *      The routines will gather statistics if SS_STATISTICS is defined.
  1334.  *      A call to this function will cause the statistics to be dumped
  1335.  *      into an external string errmsg, which must be large.
  1336.  * Return values:
  1337.  *      None
  1338.  */
  1339. void ss_dump_statistics ( void );
  1340.  
  1341. /*
  1342.  * Description:
  1343.  *      If (what & SS_DUMP_TABLE) dump the contents of the hash table to
  1344.  *      stderr. If (what & SS_DUMP_TOTALS) return a string which
  1345.  *      says how many entries etc. there are in the table.
  1346.  * Return values:
  1347.  *      - a string or NULL
  1348.  */
  1349. char * ss_dump_table ( int what );
  1350.  
  1351. /*
  1352.  * Based on (n+1)^2 = n^2 + 2n + 1
  1353.  * given that    1^2 = 1, then
  1354.  *        2^2 = 1 + (2 + 1) = 1 + 3 = 4
  1355.  *         3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9
  1356.  *         4^2 = 9 + (6 + 1) = 9 + 7 = 1 + 3 + 5 + 7 = 16
  1357.  *        ...
  1358.  * In other words, a square number can be express as the sum of the
  1359.  * series n^2 = 1 + 3 + ... + (2n-1)
  1360.  */
  1361. int isqrt ( int n );
  1362.  
  1363. /*
  1364.  * A replacement of strdup(), since it's not defined at some
  1365.  * unix variants.
  1366.  */
  1367. char *strdup_local ( char *str );
  1368.  
  1369. /*
  1370.  * A replacement of strtol() since it's not defined at
  1371.  * many unix systems.
  1372.  */
  1373. long strtol_local ( char *str, char **ptr, int base );
  1374.  
  1375. /*
  1376.  * Initialise all variables used in the timing routines. 
  1377.  */
  1378. void reset_sleep ( void );
  1379.  
  1380. void log_time ( long process_utime );
  1381.  
  1382. /*
  1383.  * enough_elapsed_time will return true if the time passed since
  1384.  * last tick is more than max-time.
  1385.  */
  1386. int enough_elapsed_time ( void );
  1387.  
  1388. /*
  1389.  * sleep_delta checks how much time has elapsed since last tick.
  1390.  * If it is less than max_time, the remaining time is slept with select().
  1391.  */
  1392. void sleep_delta ( void );
  1393.  
  1394. void set_max_time ( long t );
  1395.  
  1396. void time_info ( object *op );
  1397.  
  1398. long seconds ( void );
  1399.  
  1400. /*
  1401.  * Allocate and return the pointer to an empty treasurelist structure.
  1402.  */
  1403. treasurelist *get_empty_treasurelist ( void );
  1404.  
  1405. /*
  1406.  * Allocate and return the pointer to an empty treasure structure.
  1407.  */
  1408. treasure *get_empty_treasure ( void );
  1409.  
  1410. /*
  1411.  * Reads the lib/treasures file from disk, and parses the contents
  1412.  * into an internal treasure structure (very linked lists)
  1413.  */
  1414. treasure *load_treasure ( FILE *fp );
  1415.  
  1416. /*
  1417.  * Opens LIBDIR/treasure and reads all treasure-declarations from it.
  1418.  * Each treasure is parsed with the help of load_treasure().
  1419.  */
  1420. void load_treasures ( void );
  1421.  
  1422. /*
  1423.  * Searches for the given treasurelist in the globally linked list
  1424.  * of treasurelists which has been built by load_treasures().
  1425.  */
  1426. treasurelist *find_treasurelist ( char *name );
  1427.  
  1428. /*
  1429.  * Searches, with the help of find_treasurelist, for the given
  1430.  * treasurelist.  Returns the first of the treasures within
  1431.  * the linked list of treasures in the found list.
  1432.  * Returns NULL on failure.
  1433.  */
  1434. treasure *find_treasure ( char *name );
  1435.  
  1436. /*
  1437.  * Generates the objects specified by the given treasure.
  1438.  * It goes recursively through the rest of the linked list.
  1439.  * If there is a certain percental chance for a treasure to be generated,
  1440.  * this is taken into consideration.
  1441.  * The second argument specifies for which object the treasure is
  1442.  * being generated.
  1443.  * If flag isn't GT_ENVIRONMENT, monster_check_apply() is called.
  1444.  * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only
  1445.  * abilities.  This is used by summon spells, thus no summoned monsters
  1446.  * start with equipment, but only their abilities).
  1447.  */
  1448. void create_treasure ( treasure *t, object *op, int flag, int difficulty );
  1449.  
  1450. /*
  1451.  * Based upon the specified difficulty and upon the difftomagic_list array,
  1452.  * a random magical bonus is returned.  This is used when determine
  1453.  * the magical bonus created on specific maps.
  1454.  */
  1455. int magic_from_difficulty ( int difficulty );
  1456.  
  1457. /*
  1458.  * Sets magical bonus in an object, and recalculates the effect on
  1459.  * the armour variable, and the effect on speed of armour.
  1460.  * This function doesn't work properly, should add use of archetypes
  1461.  * to make it truly absolute.
  1462.  */
  1463. void set_abs_magic ( object *op, int magic );
  1464.  
  1465. /*
  1466.  * Sets a random magical bonus in the given object based upon
  1467.  * the given difficulty, and the given max possible bonus.
  1468.  */
  1469. void set_magic ( int difficulty, object *op, int max_magic );
  1470.  
  1471. /*
  1472.  * Randomly adds one magical ability to the given object.
  1473.  */
  1474. void set_ring_bonus ( object *op, int bonus );
  1475.  
  1476. /*
  1477.  * get_magic(diff) will return a random number between 0 and 4.
  1478.  * diff can be any value above 2.  The higher the diff-variable, the
  1479.  * higher is the chance of returning a low number.
  1480.  * It is only used in fix_generated_treasure() to set bonuses on
  1481.  * rings and amulets.
  1482.  * Another scheme is used to calculate the magic of weapons and armours.
  1483.  */
  1484. int get_magic ( int diff );
  1485.  
  1486. /*
  1487.  * generate_treasure() creates an object based upon the given list of
  1488.  * objectnames (or new objectlists) and the given difficulty.
  1489.  * The lists are specified in the include/treasure.h file.
  1490.  * NULL is returned on failure.
  1491.  */
  1492. object *generate_treasure ( int list, int difficulty );
  1493.  
  1494. /*
  1495.  * fix_generated_item():  This is called after an item is generated, in
  1496.  * order to set it up right.  This produced magical bonuses, puts spells
  1497.  * into scrolls/books/wands, makes it unidentified, hides the value, etc.
  1498.  */
  1499. void fix_generated_item ( object *op, int difficulty, int max_magic );
  1500.  
  1501. /*
  1502.  * Used in artifact generation.  The bonuses of the first object
  1503.  * is modified by the bonuses of the second object.
  1504.  */
  1505. void add_abilities ( object *op, object *change );
  1506.  
  1507. /*
  1508.  * Gives some items special abilities, powers and curses
  1509.  */
  1510. void generate_artifact ( object *op );
  1511.  
  1512. /*
  1513.  * If the artifact-lists haven't been initialised already, a call
  1514.  * to this function will result in a call to read_artifacts()
  1515.  */
  1516. void init_artifacts ( void );
  1517.  
  1518. /*
  1519.  * For debugging purposes.  Dumps all tables.
  1520.  */
  1521. void dump_artifacts ( void );
  1522.  
  1523. /*
  1524.  * Builds up the lists of artifacts from the file in the libdir.
  1525.  */
  1526. void read_artifacts ( void );
  1527.  
  1528. /*
  1529.  * Converts between Fontindex and XChar2b types.
  1530.  */
  1531. XChar2b fontindex_to_XChar2b ( Fontindex s );
  1532.  
  1533. /*
  1534.  * read_bmaps(): When bitmaps are used instead of fonts, this function
  1535.  * does the actual reading of all the bitmap-files, and sets up the
  1536.  * player->bitmaps array.  It assumes the bitmap directory and the
  1537.  * bmaps file are found in the LIBDIR directory.
  1538.  */
  1539. void read_bmaps ( player *pl );
  1540.  
  1541. /*
  1542.  * This function adds the path to the fontpath of the given display.
  1543.  * It's mostly copied from the X11R5 distribution.
  1544.  */
  1545. void set_font_path ( Display *dpy, char *path );
  1546.  
  1547. /*
  1548.  * Checks if "crossfire" is present somewhere in the fontpath of
  1549.  * the given display.
  1550.  */
  1551. int check_font_path ( Display *dpy );
  1552.  
  1553. /*
  1554.  * Uses check_font_path() and set_font_path() to check and, if needed
  1555.  * fix the fontpath for a player.
  1556.  * If it fails, it sets the "use_pixmaps" flag in the player structure,
  1557.  * which will prompt the read_bmaps() function at a later time.
  1558.  */
  1559. int fixfontpath ( player *pl );
  1560.  
  1561. /*
  1562.  * allocate_colors() tries to get enough colors for the game-window.
  1563.  * If it fails, it tries to use a private colormap.
  1564.  * If that also fails, it switches mode to black/white.
  1565.  */
  1566. void allocate_colors ( player *p, Window w );
  1567.  
  1568. #endif /* __STDC__ */
  1569. #endif /* __CEXTRACT__ */
  1570.